// pages/my/consumer.js
import regeneratorRuntime from '../../utils/regenerator-runtime/runtime-module';

var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        commonImgUrl: '',//全局图片网络路径
        //    文档上面没有说明每个状态对应的值 就从1开始排列了
        tablist: [
            {
                id: 1,
                label: '全部'
            }, {
                id: 2,
                label: '待付款'
            }, {
                id: 3,
                label: '待发货'
            }, {
                id: 4,
                label: '待收货'
            }, {
                id: 5,
                label: '待评价'
            },
        ],
        currentTabID: 1,//当前选中tab
        nowPage: 1,//当前页
        pageShow: 10,//每页展示数量
        hasMoreData: true,
        artlist: [],//订单列表
        currentOrderId:'',//当前操作的订单ID
    },
    /**
     * @author 焦政
     * @Description: 订单状态选择
     */
    e_seletab(e) {
        this.setData({
            currentTabID: e.currentTarget.dataset.tabid
        })
    },
    /**
     * @author 焦政
     * @Description: 获取各种状态消费品订单
     */
    async getOrderListByCustomerUuid() {
        var optionss = {
            data: {
                customerUuid: wx.getStorageSync('customerUuid'),
                nowPage: this.data.nowPage,
                pageShow: this.data.pageShow,
                type: 1,
                state: this.data.currentTabID
            }
        };
        let resArtlist = await app.$net.post('getOrderListByCustomerUuid', 1, optionss, 'wxshop');
        console.log(resArtlist)
        if (resArtlist.return_code == 0) {
            var contentlistTem = this.data.artlist;
            if (this.data.nowPage == 1) {
                contentlistTem = []
            }
            var contentlist = resArtlist.data.orderList;
            if (this.data.nowPage >= resArtlist.data.totalPage) {
                this.setData({
                    artlist: contentlistTem.concat(contentlist),
                    hasMoreData: false
                })
            } else {
                this.setData({
                    artlist: contentlistTem.concat(contentlist),
                    hasMoreData: true,
                    nowPage: this.data.nowPage + 1
                })
            }
        }
    },
    /**
     * @author 焦政
     * @Description: 收货
     */
    e_Receipt(e) {
        this.setData({
            currentOrderId: e.currentTarget.dataset.orderId
        })
        wx.showModal({
            title: '提示',
            content: '确认收货？',
            success: function (res) {
                if (res.confirm) {
                    console.log('用户点击确定')
                    this.doReceipt()
                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })
    },
    /**
     * @author 焦政
     * @Description: 执行收货
    */
    async doReceipt(){
        var optionss = {
            data: {
                customerUuid:wx.getStorageSync('customerUuid'),
                orderId:this.data.currentOrderId
            }
        };
        let resReceipt = await app.$net.post('getOrderListByCustomerUuid', 1, optionss, 'wxshop');
        if(resReceipt.return_code == 0){

        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        //配置全局图片网络路径
        this.setData({
            commonImgUrl: app.$imgURL
        })
        this.getOrderListByCustomerUuid()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if (this.data.hasMoreData) {
            this.getOrderListByCustomerUuid()
        } else {
            wx.showToast({
                title: '没有更多数据',
            })
        }
    },
    goDetails(e) {
        //订单ID临时固定
        wx.navigateTo({
            url: 'consumerDetails?orderUuid=132a065f4bc14c538803230f451740a4'
        })
    }
})